const breadModel = require('../model/breadModel');


//获取面包数据
module.exports.find = async function (page,searchParams) {
    let { current, pageSize } = page;
    // 根据查询条件获取总数
    let total = await breadModel.countDocuments(searchParams);
    // 根据查询条件获取具体数量的数据
    let data = await breadModel.find(searchParams)
        .populate({ path: "storeId" })
        .limit(pageSize)
        .skip((current - 1) * pageSize)
        ;
    return {
        current, pageSize, total, data
    }
}

// id查找
module.exports.findById = async function (id) {
    return await breadModel.findById(id);
}

// 添加
module.exports.insert = async function(bread){
    return await breadModel.create(bread);
}

// 删除
module.exports.delete = async function(id){
    return await breadModel.deleteOne({_id:id});
}
// 修改
module.exports.update = async function(bread){
    return await breadModel.updateOne({_id:bread._id},bread);
}